package com.sqkj.service;

import com.sqkj.dao.ArticleDao;
import com.sqkj.entity.Article;
import com.sqkj.entity.articleInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ArticleService {
    @Resource
    ArticleDao dao;


    @Transactional
    public Boolean add(Article article) {
        if (dao.add(article.getArticleTitle(),article.getAuthorId(),article.getArticleViewCount(),article.getArticleCreateTime(),article.getArticleContent(),article.getArticleGoodCnt(),article.getArticleCommentCount(),article.getArticleStatus(),article.getType(),article.getTag(),article.getArticleAbstract(),article.getHeadImgUrl(),article.getAudioUrl())>0){
            return true;
        }else {
            return false;
        }
    }

    public List<Article> findAll() {
        return dao.findAll();
    }
    public Article findById(int id) {
        return dao.findById(id);
    }
    @Transactional
    public Boolean deleteById(int id){
        if (dao.deleteById(id)>0){
            return true;
        }else {
            return false;
        }
    }

    public List<articleInfo> randFind() {
        return  dao.randFind();
    }

    public List<Article> findAllByAuthorId(int authorId) {
        return dao.findAllByAuthorId(authorId);
    }

    @Transactional
    public Boolean addViewCount(int articleViewCount , int id ) {

        if (dao.addViewCount(articleViewCount, id)>0) {
            return true;
        } else {
            return false;
        }
    }
   @Transactional
    public Boolean addGoodCut(int articleGoodCnt , int id ) {
       if (dao.addGoodCount(articleGoodCnt, id)>0) {
           return true;
       } else {
           return false;
       }
    }
    @Transactional
    public Boolean reduceGoodCut(int articleGoodCnt , int id ) {
        if (dao.reduceGoodCount(articleGoodCnt, id)>0) {
            return true;
        } else {
            return false;
        }
    }
}
